<div class="actions">
	<ul>
		<li><?php echo $html->link(__('Lista de Usuarios', true), array('action'=>'index'));?></li>
	</ul>
</div>

<?php
	//pr($tournaments);
	echo $form->create('User', array('action'=>'admin'))."\r\n";
	
	
	echo $form->input('id', array('type'=>'hidden'))."\r\n";
	echo $form->input('Event.id', array('type'=>'hidden'))."\r\n";
	if($this->data['User']['citizenship']!='Venezuela'){
		echo $form->tag('div', "Este usuario es de nacionalidad:{$this->data['User']['citizenship']}", array('class'=>'notifyCitizenship'))."\r\n";
	}
	?>
	<fieldset>
		<legend>
			<?=trim($this->data['User']['name'].' '.$this->data['User']['lastname']);?>
		</legend>
	
	<table class="tableIndex">
		<thead>
			<?=$html->tableHeaders(array(__('Torneo',true), __('Tipo',true), __('Seleccionado',true),__('Activo',true), __('Equipo',true)))."\r\n";?>
		</thead>
		<tbody>
			
			<? 	$cont = 0;
				foreach ($tournaments as $t):?>
				<? //pr($t);?>
				<tr>
					<td>
						<?=$t['Tournament']['name']."\r\n";?>
					</td>
					<td>
						<?
							switch ($t['Tournament']['type']) {
								case 'OFC':
								echo 'Oficial'."\r\n";
								break;
								case 'NAC':
								echo 'Nacional'."\r\n";
								break;
								case 'COS':
								echo 'Video Game Cosplay'."\r\n";
								break;
							};
						?>
					</td>
					<td>
						<?php
							$check = false;
							$checkselect = false;
							$userTournamentId = '';
							$status = '';
							$depositTournamentId = '';
							if(!empty($this->data['Tournament'])){
								foreach ($this->data['Tournament'] as $tdT) {
									if($tdT['id']==$t['Tournament']['id']){
										$checkselect = 'checked';
										$check = ($tdT['UserTournament']['status']==1)?'checked':false;
										$userTournamentId = $tdT['UserTournament']['id'];
										$status = $tdT['UserTournament']['status'];
										$tournamentGroupId = $tdT['UserTournament']['tournamentgroup_id'];
										$depositTournamentId = $tdT['UserTournament']['deposit_id'];
									}
								}
							}
							echo $form->input('Tournament.'.$cont.'.select', array('type'=>'checkbox', 'disabled'=>true, 'label'=>false, 'checked'=>$checkselect))."\r\n";
						?>
					</td>
					<td>
						<? 
							
							echo $form->input('Tournament.'.$cont.'.name', array('type'=>'hidden', 'value'=>$t['Tournament']['name']))."\r\n";
							echo $form->input('Tournament.'.$cont.'.UserTournament.id', array('type'=>'hidden', 'value'=>$userTournamentId))."\r\n";
							echo $form->input('Tournament.'.$cont.'.UserTournament.status', array('type'=>'hidden', 'value'=>$status))."\r\n";
							echo $form->input('Tournament.'.$cont.'.DepositTournament.id', array('type'=>'hidden', 'value'=>$depositTournamentId))."\r\n";
							echo $form->input('Tournament.'.$cont.'.id', array('type'=>'checkbox', 'label'=>false, 'value'=>$t['Tournament']['id'], 'checked'=>$check))."\r\n";
						?>
					</td>
					<td>
						<?	//SI ES UN TORNEO DE GRUPO Y SI YA EXSTE EL REGSITRO DEL TONEO AGREGADO
							if($t['Tournament']['participants']>1 && !empty($userTournamentId))
								if(empty($tournamentGroupId)){// SI YA TIENE GRUPO
									echo $html->link('ver',"/tournamentgroups/add/{$t['Tournament']['id']}/{$this->data['User']['id']}")."\r\n";
								}
								else{
									echo $html->link('ver', array('controller'=>'tournamentgroups', 'action'=>'edit', $tournamentGroupId))."\r\n";
								}
							else
								echo '&nbsp;'."\r\n";
						?>
					</td>
				</tr>
			<? 
				$cont++;
			endforeach;
			?>
		</tbody>
	</table>
	</fieldset>
	<?
	echo $form->end('Guardar');
?>